﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;

namespace GataBaseSys
{
    public partial class ShangTian : System.Web.UI.Page
    {
        AddressBLL adbll = new AddressBLL();
        CommodityBLL cdbll = new CommodityBLL();
        AuctionBLL acbll = new AuctionBLL();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                this.Droplistdiqu.DataSource = adbll.auctions();
                this.Droplistdiqu.DataValueField = "AddressID";
                this.Droplistdiqu.DataTextField = "AddressCategory";
                this.Droplistdiqu.DataBind();
                this.Droplistleixing.DataSource = cdbll.auctions();
                this.Droplistleixing.DataTextField = "CommodityCategory";
                this.Droplistleixing.DataValueField = "CommodityID";
                this.Droplistleixing.DataBind();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                string fileName = Server.MapPath("/Img/upImg");
                if (!Directory.Exists(fileName))
                {
                    Directory.CreateDirectory(fileName);
                }
                string imgName = DateTime.Now.ToString("yyyy-MM-dd") + FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf("."));
                FileUpload1.SaveAs(fileName+imgName);
                Image1.ImageUrl = ("/Img/upimg") + imgName;
                
            }

        }

        protected void BtuQue_Click(object sender, EventArgs e)
        {
            Auction au = new Auction();
            au.AuctionName = this.title.Value.Trim();
            au.AuctionPicture = this.Image1.ImageUrl;
            au.AuctionIntroduce = this.username.Value.Trim();
            au.AuctionPrice = Convert.ToDecimal(this.phone.Value.Trim());
            au.AuctionState = this.Droplistzhuang.SelectedItem.Text;
            au.AuctionCategory = Convert.ToInt32(this.Droplistdiqu.SelectedItem.Value.ToString());
            au.AuctionCode = Convert.ToInt32(this.Droplistleixing.SelectedItem.Value.ToString());
            au.AuctionUpload = Convert.ToDateTime(this.shangdate.Value.Trim().ToString());
            au.AuctionAuction = Convert.ToDateTime(this.paimai.Value.Trim().ToString());
            if (acbll.Inset(au))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功')</script>");
            }

        }

        
    }
}